package com.gls.security.server.authorization.translator;

import com.gls.security.server.authorization.jpa.entity.Account;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Component;

/**
 * 用户value object 和 entity 的转换类
 *
 * @author lizhiyong
 */
@Component
public class AccountTranslator {

    public UserDetails translator(Account account) {
        if (account == null) {
            return null;
        }
        UserDetails userDetails = new User(
                account.getUsername(),
                account.getPassword(),
                account.getEnabled(),
                account.getAccountNonExpired(),
                account.getCredentialsNonExpired(),
                account.getAccountNonLocked(),
                AuthorityUtils.commaSeparatedStringToAuthorityList("admin")
        );
        return userDetails;
    }

}
